<?php


class ssoAction extends BackAction{
    
    /**
     * 登陆获取授权oauth
     */
    function actionIndex(){
        $username       = $this->getVar('username');
        $token          = $this->getVar('token');
        $expires_in     = $this->getVar('expires_in');
        
        if($username && $token && $expires_in){
            $c          = new SaeTClientV2(WB_AKEY, WB_SKEY, $token);
            $re         = $c->get_uid();
            $expires_in = date('YmdH',time()-60 + $expires_in);
            $oauth  = ORM_Finder::findOne('DB_OAUTH', array('username'=>$username));
            if(!$oauth){
                $oauth  = new DB_OAUTH();
                $oauth->setUsername($username);
            }
            $oauth->setToken($token);
            $oauth->setWeiboId($re['uid']);
            $oauth->setExpiresIn($expires_in);
            $oauth->save();
            $_SESSION['oauth2'] = $oauth->toArray();
            echo 'ok';
        }
    }
}
?>
